Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
json-colorizer
Advanced tools
The json-colorizer npm package is a tool that allows you to colorize JSON strings for better readability in the terminal. It helps in debugging and logging by making JSON data more visually appealing and easier to understand.
Basic Colorization
This feature allows you to colorize a JSON string with default settings. The output will be a colorized version of the JSON string, making it easier to read in the terminal.
const colorize = require('json-colorizer');
const jsonString = '{"name": "John", "age": 30, "city": "New York"}';
console.log(colorize(jsonString));
Custom Colorization
This feature allows you to customize the colors used for different parts of the JSON string. In this example, string keys are colored cyan and string literals are colored magenta.
const colorize = require('json-colorizer');
const jsonString = '{"name": "John", "age": 30, "city": "New York"}';
const options = { colors: { STRING_KEY: 'cyan', STRING_LITERAL: 'magenta' } };
console.log(colorize(jsonString, options));
Pretty Print with Colorization
This feature allows you to pretty-print the JSON string with colorization. The output will be a well-formatted and colorized JSON string, making it even more readable.
const colorize = require('json-colorizer');
const jsonString = '{"name": "John", "age": 30, "city": "New York"}';
const options = { pretty: true };
console.log(colorize(jsonString, options));
Chalk is a popular npm package for styling terminal strings. While it is not specifically designed for JSON, it can be used to colorize any string, including JSON, by manually specifying the colors for different parts of the string. It offers more flexibility but requires more setup compared to json-colorizer.
CLI Highlight is a package that provides syntax highlighting for code in the terminal. It supports multiple languages, including JSON. It offers more comprehensive syntax highlighting features compared to json-colorizer but may be overkill if you only need to colorize JSON.
PrettyJSON is a package that formats and colorizes JSON data for the terminal. It offers similar functionality to json-colorizer but focuses more on formatting and less on customization of colors.
A library for colorizing JSON strings
This package is a simple console syntax highlighter for JSON.
npm install --save json-colorizer
const colorize = require('json-colorizer');
console.log(colorize({ "foo": "bar" });
If you pass a string to the colorize function, it will treat it as pre-serialized JSON. This can be used in order to colorize pretty-printed JSON:
const colorize = require('json-colorizer');
const json = JSON.stringify({"foo": "bar"}, null, 2);
console.log(colorize(json);
To pretty-print the resulting JSON, pass the pretty: true
option to the options object:
const colorize = require('json-colorizer');
const json = '{"foo": "bar"}';
console.log(colorize(json, { pretty: true }));
NOTE: Prior to version 2.x, the colors were specified by referencing chalk
color functions directly. This required requiring chalk
into the file. Starting with version 2.x, the colors are specified as a string which is the name (or property path) to the desired color function.
You can specify a color to use for coloring individual tokens by providing a colors
object in the options object. This should map token types to the names of color functions (see the chalk styles reference).
A color can also be specified as a hex value starting with the #
symbol.
const colorize = require('json-colorizer');
console.log(colorize({ "foo": "bar" }, {
colors: {
STRING_KEY: 'green',
STRING_LITERAL: 'magenta.bold',
NUMBER_LITERAL: '#FF0000'
}
}));
The tokens available are:
BRACE
BRACKET
COLON
COMMA
STRING_KEY
STRING_LITERAL
NUMBER_LITERAL
BOOLEAN_LITERAL
NULL_LITERAL
FAQs
A library to format JSON with colors for display in the console
The npm package json-colorizer receives a total of 608,783 weekly downloads. As such, json-colorizer popularity was classified as popular.
We found that json-colorizer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.